;; Sri Ganeshji : Sri Balaji : Sri Pitreshwarji : Sri Durgaji : Sri Venkateshwara

/*
Objective(s) -
-	This code demonstrates the concept of Automatic Auto Column Reports using Trial 
	Balance

Last modification -
-	Altered on 09-11-2009
*/

[Report: AutoAutoCol Trial Balance]

	Title		: $$LocaleString:"Trial Balance"
	Form		: AutoAutoCol Trial Balance

	Repeat      : SVCurrentCompany, SVFromDate, SVToDate
	ColumnReport: MyAutoMultiColumns

	Variable	: AutoAutoCol TB Group, IsLedgerWise, SVPeriodicity

    PrintSet    : Report Title      : $$LocaleString:"Trial Balance"
    Set         : IsLedgerWise      : No

    Variable    : DoSetAutoColumn
    Set         : DoSetAutoColumn   : Yes
    Set         : DSPRepeatCollection: "List of Primary Companies"

;; When the attribute Column Report is mentioned, the attribute 
;; Repeat should also be mentioned. The New Column, Alter Column and 
;; Delete Column buttons will automatically get activated 
;; once Column Report & Repeat attributes are mentioned 
;; together in the report.

;; PrintSet At Report Definition will set the Variable Value
;; in Print Mode

[Form: AutoAutoCol Trial Balance]
    
    Button      : F2ChangePeriod, ChangeCompany, LedgerWiseButton
	Keys        : ChangePeriod
	
;;To incorporate the change in TallyPrime
	Bottom Button	: Add Column, Alter Column, Delete Column

	BottomButton: MyAutoAutoButton, BlankButton, InvReports, AcctReports, ReportOperations, FilterButton, ValueButton
	Buttons		: PrintButton, ExportButton, UploadButton, MailButton
	Parts		: AutoAutoCol TB Title, AutoAutoCol TB Details
	Page Break  : DSP ClPageBreak, AutoAutoCol TB OpPgPart
	Height		: 100% Page
	Width		: 100% Page
	Space Top	: 0
	Space Left	: 0
	Background	: Released Pale Yellow
	Option		: Prn AutoAutoCol TB		: $$InPrintMode
    Option      : Set Auto Option   		: $$SetAutoColumns:SVCurrentCompany
    
    [!Form: Set Auto Option]
	
	[!Form: Prn AutoAutoCol TB]
	
        Add         : Parts     : At Beginning  : DSP CompanyName, DSP CompanyAddress, DSP ReportTitle
   		Space Left	: 0.25 inch
   		
;; For enabling Titles during Printing, Form Level Optional parts 
;; Company Name, Address and Report Title are used from defTDL.
       
    [Part: AutoAutoCol TB OpPgPart]
    
        Parts       : DSP CompanyName, DSP CompanyAddress, DSP ReportTitle, AutoAutoCol TB Title
        Vertical    : Yes

;; Every continuous page should have the above parts during Printing

	[Part: AutoAutoCol TB Title]

		Lines		: AutoAutoCol TB Title1, AutoAutoCol TB Title2, AutoAutoCol TB Title3, AutoAutoCol TB STitle
		Border      : Thin Top

		[Line: AutoAutoCol TB Title1]

			Use			: AutoAutoCol TB Title3
			Local		: Field		: Name Field		    : Set as		: ""
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Set as		: @@CmpMailName
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Lines			: 0
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Border		: Thin Left
			Invisible   : $$IsCommon:SVCurrentCompany AND $$InPrintMode
			
;; This Line is made Invisible in Print Mode only if Columns selected
;; are of single company

		[Line: AutoAutoCol TB Title2]

			Use			: AutoAutoCol TB Title3
			Local		: Field		: Default		    	: Style			: Normal
			Local		: Field		: Name Field		    : Set as		: $$LocaleString:"Particulars"
			Local		: Field		: Name Field		    : Style			: Normal Bold
			Local		: Field		: Name Field	    	: WideSpaced	: Yes
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Set as		: @@DSPDateStr
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Border		: Left Full Thin Bottom
			
;; DSPFDateStr is the Default Formula which displays the values 
;; present in both the date variables - SVFromDate & SVTodate 

		[Line: AutoAutoCol TB Title3]

			Fields		: Name Field, AutoAutoCol TB DrAmt Field
			Local		: Field		: Default			    : Type			: String
			Local		: Field		: Name Field		    : Set as		: ""
			Local		: Field		: Name Field		    : Align			: Center
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Align			: Centre
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Border		: Left Full Thin Bottom
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Set as		: $$LocaleString:"Closing Balance"
			Repeat		: AutoAutoCol TB DrAmt Field

		[Line: AutoAutoCol TB STitle]

			Fields		: Name Field, AutoAutoCol TB Amount Field
			Local		: Field		: Default			    : Style			: Normal
			Local		: Field		: Default			    : Align			: Centre
			Local		: Field		: Default			    : Type			: String
			Local		: Field		: Name Field		    : Set as		: ""
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Set as		: $$LocaleString:"Debit"
			Local		: Field		: AutoAutoCol TB CrAmt Field	: Set as		: $$LocaleString:"Credit"
			Local		: Field		: AutoAutoCol TB CrAmt Field	: Border		: Thin Left
			Repeat		: AutoAutoCol TB Amount Field
			Border		: Thin Bottom
			
	[Part: AutoAutoCol TB Details]

		Lines		: AutoAutoCol TB Details
		BottomLines	: AutoAutoCol TB Total
		Repeat		: AutoAutoCol TB Details	: AutoAutoCol TB GroupLed
		Total		: AutoAutoCol TB DrAmt Field, AutoAutoCol TB CrAmt Field
		Scroll		: Vertical
		CommonBorder: Yes
		Float		: Yes
		Page Break  : AutoAutoCol TB ClPgLine, AutoAutoCol TB OpPgLine
		
        Option      : AutoAutoCol TB Details Led : ##IsLedgerWise
        
;; Part Level Page Breaks is introduced to have Page Totals
;; at the beginning (except first page) and end (except last page)
;; of every page

;; The optional part is selected when Ledgerwise is selected by the user.
        
        [!Part: AutoAutoCol TB Details Led]

		    Repeat		: AutoAutoCol TB Details	: AutoAutoCol TB Led
		    Local       : Collection: AutoAutoCol TB Led         : BelongsTo     : Yes

;; If Ledgerwise Option is selected by the user, Collection should
;; have attribute BelongsTo set to Yes as the Ledgers pertaining to
;; all the Groups and Sub-Groups needs to be displayed together
		    
        [Line: AutoAutoCol TB ClPgLine] ;; Line for Closing Page Totals
        
            Use         : AutoAutoCol TB Details
            Delete      : Fields    : AutoAutoCol TB Amount Field
            Add         : Fields    : AutoAutoCol TB AmountSTField
            Delete      : Repeat    : AutoAutoCol TB AmountSTField
            Add         : Repeat    : AutoAutoCol TB AmountSTField

            Local       : Field     : Default               : Style         : Normal Bold
			Local		: Field		: AutoAutoCol TB Name Field	: Set as		: "Carried Over"
			Local		: Field		: AutoAutoCol TB Name Field	: WideSpaced    : Yes
			Local		: Field		: AutoAutoCol TB DrAmtSTField: Set as		: $$Total:AutoAutoColTBDrAmtField
			Local		: Field		: AutoAutoCol TB DrAmtSTField: Border        : Totals
			Local		: Field		: AutoAutoCol TB CrAmtSTField: Set as		: $$Total:AutoAutoColTBCrAmtField
			Local		: Field		: AutoAutoCol TB CrAmtSTField: Border        : Totals					    		
			Space Top   : 1

        [Line: AutoAutoCol TB OpPgLine] ;; Line for Opening Page Totals
        
            Use         : AutoAutoCol TB ClPgLine
			Local		: Field		: AutoAutoCol TB DrAmtSTField: Delete        : Border
			Local		: Field		: AutoAutoCol TB CrAmtSTField: Delete        : Border
			Local		: Field		: AutoAutoCol TB Name Field	: Set as		: "Brought Foward"
			Space Top   : 0
			Space Bottom: 1
						
            [Field: AutoAutoCol TB AmountSTField] ;; New Field Definition for the Page Totals
            
				Fields		: AutoAutoCol TB DrAmt STField, AutoAutoCol TB CrAmt STField
				Border		: Thin Left
				
                [Field: AutoAutoCol TB DrAmtSTField]
                
                    Use         : AutoAutoCol TB DrAmt Field

                [Field: AutoAutoCol TB CrAmtSTField]
                
                    Use         : AutoAutoCol TB CrAmt Field
                                    
		[Line: AutoAutoCol TB Details]

			Fields		: AutoAutoCol TB Name Field, AutoAutoCol TB Amount Field
			Local		: Field		: AutoAutoCol TB Name Field	: Set as		: $$Name
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Set as		: if $$IsDr:$ClosingBalance then $ClosingBalance else 0
			Local		: Field		: AutoAutoCol TB CrAmt Field	: Set as		: if $$IsDr:$ClosingBalance then 0 else $ClosingBalance
			Repeat		: AutoAutoCol TB Amount Field

;; Repeat Attribute of Line will position the Field to the Right, 
;; as if it is a Right Field.
	
			[Field: AutoAutoCol TB Name Field]

				Use			: Name Field
				Variable	: AutoAutoCol TB Group
				Display		: AutoAutoCol Trial Balance		: $$IsGroup
				Option		: AutoAutoCol TB LedName Field	: $$IsLedger

				[!Field: AutoAutoCol TB LedName Field]

					Variable	: LedgerName
					Display		: Ledger Monthly Summary
					Style       : Normal Italic

			[Field: AutoAutoCol TB Amount Field]

				Fields		: AutoAutoCol TB DrAmt Field, AutoAutoCol TB CrAmt Field
				Border		: Thin Left
				Display		: AutoAutoCol Trial Balance		: $$IsGroup
				Display		: Ledger Monthly Summary    : $$IsLedger
			    			    
				[Field: AutoAutoCol TB DrAmt Field]

					Use			: Amount Field
					Style       : Normal

				[Field: AutoAutoCol TB CrAmt Field]

					Use			: Amount Field
					Style       : Normal

			[Collection: AutoAutoCol TB GroupLed]
			
				Collection	: AutoAutoCol TB Group, AutoAutoCol TB Led
			
			[Collection: AutoAutoCol TB Group]
			
				Type		: Group
				Child Of	: ##AutoAutoColTBGroup
				Filter		: NoProfit
				Fetch		: Name, ClosingBalance
				
;; NoProfit Formula is used to Filter all the Ledgers
;; except Profit and Loss Account.
			
			[Collection: AutoAutoCol TB Led]
			
				Type		: Ledger
				Child Of	: ##AutoAutoColTBGroup
				Filter		: NoProfit
				Fetch		: Name, ClosingBalance


			[Variable: AutoAutoCol TB Group]
			
				Type		: String
				Default     : ""
				Volatile	: Yes
	
;;			[System: Formula]
;;
;;				NoProfit	: NOT $$IsLedgerProfit AND $ClosingBalance > 0

;; Function IsLedgerProfit returns Yes, only if the current object
;; is a Profit & Loss Ledger Account.

    	[Line: AutoAutoCol TB Total]

			Use			: AutoAutoCol TB Details
			Local       : Field     : Default               : Style         : Normal Bold
			Local		: Field		: AutoAutoCol TB Name Field	: Set as		: "GRAND TOTAL"
			Local       : Field     : AutoAutoCol TB Name Field	: WideSpaced    : Yes
			Local		: Field		: AutoAutoCol TB Name Field	: Align			: Centre
			Local		: Field		: AutoAutoCol TB DrAmt Field	: Set as		: $$Total:AutoAutoColTBDrAmtField
			Local		: Field		: AutoAutoCol TB CrAmt Field	: Set as		: $$Total:AutoAutoColTBCrAmtField
			Border		: Flush Totals
			Fixed		: Yes
			Space Top   : 1

;; Fixed Attribute at Line Definition will not allow the cursor to be
;; placed on that line while viewing and scrolling

;; End-of-Trial-Balance

;; Report for displaying Column Option

[Report: MyAutoMultiColumns]

    Title       : $$LocaleString:"Column Details"

[Form: MyAutoMultiColumns]

    No Confirm  : Yes
    Full Width  : No

    Space Right : 0.25
    Background  : @@SV_UNBLUE
    Parts       : MyAuto MultiColumns
    Option      : Small Size Form

[Part: MyAuto MultiColumns]

    Lines       : Form SubTitle, MyAuto MultiCompany, MyAuto MultiFromDate, MyAuto MultiToDate
    Local       : Field : Form SubTitle     : Info      : $$LocaleString:"Column Details"

    [Line: MyAuto MultiCompany]

		Fields      : Short Prompt, MyAuto MultiCompany
        Local       : Field : Short Prompt 	: Info 		: $$LocaleString:"Company :"
        SpaceBottom : 1
        Invisible   : $$SelectedCmps = 1

;; SelectedCmps is a function which returns the number of selected companies.  
;; It requires no parameters.  This means that if the Selected Companies equals
;; to 1 then this line should be made invisible

        [Field: MyAuto MultiCompany]

            Use         : Name Field
            Modifies    : SVCurrentCompany
            Table       : Company
            Show Table  : Always

;; Modifies alters the Value of a Variable to be used subsequently
            
    [Line: MyAuto MultiFromDate]

		Fields      : Short Prompt, MyAuto MultiFromDate
        Local       : Field : Short Prompt 	: Info 		: $$LocaleString:"From Date :"
        SpaceBottom : 1

        [Field: MyAuto MultiFromDate]

            Use         : Uni Date Field
            Modifies    : SVFromDate
            Width       : 9

    [Line: MyAuto MultiToDate]

		Fields      : Short Prompt, MyAuto MultiToDate
        Local       : Field : Short Prompt 	: Info 		: $$LocaleString:"To Date :"
        SpaceBottom : 0.25
        
        [Field: MyAuto MultiToDate]

            Use         : MyAuto MultiFromDate
            Modifies    : SVToDate
            
;; Changes to achieve AutoColumn

[Button: MyAutoAutoButton]

	Key         : Alt+N
    Action      : Auto Columns : MyAutoAutoColumns
    Title       : $$LocaleString:"Auto Column"
    Inactive    : $$NumItems:MyAutoAutoColumns < 1

;; Action Auto Columns is an action which takes a report as its value
;; and gives auto columns in the base report accordingly.
;; MyAutoAutoColumns is a report being displayed when the button
;; MyAutoAutoButton is clicked. 

[Collection: MyAutoAuto Columns]

    Title       : $$LocaleString:"Column Details"
	Object		: MyAutoCurrentCompany, MyAutoQuarterly, MyAutoMonthly, MyAutoYearly, MyAutoHalfYearly
	Filter		: Belongs
	Format      : $$Name, 15
	Client Only	: Yes

;; Belongs is a system formula which filters the objects
;; based on the value of the Methods BelongsIf of all the objects

;; Function Name returns the Name of any given objects

[Object: MyAutoCurrentCompany]

    Name        : $$LocaleString:"Company"
    VarName     : "SVCurrentCompany"
    CollName    : "List of Primary Companies"
    BelongsIf   : $$NumItems:ListOfPrimaryCompanies > 1
    IsAgeWise   : No
    Periodicity : ""

;; Function NumItems returns the number of selected companies
;; BelongsIf is a method of object MyAutoCurrentCompany, which
;; is used to control the display of the object in the collection

[Object: MyAutoQuarterly]

    Name        : $$LocaleString:"Quarterly"
    VarName     : "SVFromDate, SVToDate"
    CollName    : "Period Collection"
    BelongsIf   : "Yes"
    IsAgeWise   : No
    Periodicity : "3 Month"

[Object: MyAutoHalfYearly]

    Name        : $$LocaleString:"Half-Yearly"
    VarName     : "SVFromDate, SVToDate"
    CollName    : "Period Collection"
    BelongsIf   : "Yes"
    IsAgeWise   : No
    Periodicity : "6 Month"

[Object: MyAutoMonthly]

    Name        : $$LocaleString:"Monthly"
    VarName     : "SVFromDate, SVToDate"    
    CollName    : "Period Collection"
    BelongsIf   : "Yes"
    IsAgeWise   : No
    Periodicity : "Month"

[Object: MyAutoYearly]

    Name        : $$LocaleString:"Yearly"
    VarName     : "SVFromDate, SVToDate"    
    CollName    : "Period Collection"
    BelongsIf   : "Yes"
    IsAgeWise   : No
    Periodicity : "Year"

;; Report AutoColumn

[Report: MyAutoAutoColumns]

    Auto        : Yes
    Title       : $$LocaleString:"Auto Repeat Columns"

[Form: MyAutoAutoColumns]

    No Confirm  : Yes
    Full Width  : No

    Space Top   : 1
    Space Bottom: 1
    Space Left  : 1
    Space Right : 1

    Background  : @@SV_UNYELLOW
    Parts       : MyAuto AutoColumns
    Output      : MyAuto AutoColumns
    Option      : Small Size Form

;; Output Attribute at Form Definition is used to return a Field value  
;; to the calling Report

;; No Confirm Attribute at Form Definition will not prompt the user to 
;; save the auto-column screen

[Part: MyAuto AutoColumns]

    Lines       : Form SubTitle, MyAuto AutoColumns
    Local       : Field : Form SubTitle         : Info      : $$LocaleString:"Auto Repeat Columns"

    [Line: MyAuto AutoColumns]

		Fields      : Medium Prompt, MyAuto SelectAuto, MyAuto AutoColumns, MyAuto CollName, MyAuto StartPeriod, MyAuto EndPeriod, MyAuto SetPeriodicity
        Local       : Field : Medium Prompt 	: Info 		: $$LocaleString:"Repeat Using :"
        SpaceBottom : 0.25

        [Field: MyAuto SelectAuto]

            Use         : Short Name Field
            Table       : MyAutoAutoColumns
            Show Table  : Always

        [Field: MyAuto AutoColumns]

			Use			: Short Name Field
			Invisible   : Yes
            Set as      : $$Table:MyAutoSelectAuto:$VarName
            Set always  : Yes
			Skip        : Yes

;; Function Table selects the Object Name from the previous Field MyAutoSelectAuto
;; and displays the corresponding method value of VarName

        [Field: MyAuto CollName]

			Use			: Short Name Field
			Invisible   : Yes
            Set as      : $$Table:MyAutoSelectAuto:$CollName
			Modifies    : DSPRepeatCollection
            Set always  : Yes
			Skip        : Yes

;; We are modifying the value of the default variable DSPRepeatCollection
;; by the value of the Method CollName from the selected Object
;; DSPRepeatCollection is repeated in the Default Variables SVCurrentCompany,
;; SVFromDate and SVToDate, which gets new values for each column

        [Field: MyAuto StartPeriod]

            Use         : Short Date Field
			Invisible   : Yes
            Set as      : if $$IsEmpty:$$Table:MyAutoSelectAuto:$Periodicity then ##SVFromDate else +
                          if $$Table:MyAutoSelectAuto:$Periodicity = "Day" then ##SVFromDate else +
                          $$LowValue:SVFromDate
            Set always  : Yes
			Modifies    : SVFromDate
			Skip        : Yes

;; Value of Variable SVFromDate is set here based on the Periodicity Method.
;; LowValue is a Function that returns beginning date of the Current Period

        [Field: MyAuto EndPeriod]

            Use         : Short Date Field
			Invisible   : Yes
            Set as      : if $$IsEmpty:$$Table:MyAutoSelectAuto:$Periodicity then ##SVToDate else +
                          if $$Table:MyAutoSelectAuto:$Periodicity = "Day" then $$MonthEnd:#DSPStartPeriod else $$HighValue:SVToDate
            Set always  : Yes
			Modifies    : SVToDate
			Skip        : Yes

;; Value of Variable SVToDate is set here based on the Periodicity Method.
;; MonthEnd is a Function gives the last day for a given month

        [Field: MyAuto SetPeriodicity]

            Use         : Short Name Field
			Invisible   : Yes
            Set as      : if NOT $$IsEmpty:$$Table:MyAutoSelectAuto:$Periodicity then $$Table:MyAutoSelectAuto:$Periodicity else "Month"
            Set always  : Yes
			Modifies    : SVPeriodicity

;; End-of-File
